package Assignment3;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Map<String, Student> hashMap = new HashMap<>();
        Student s1 = new Student("彩云","2103",19);
        Student s2 = new Student("青云","2108",21);
        Student s3 = new Student("神仙居","2119",20);
        Student s4 = new Student("古思域","2173",18);
        Student s5 = new Student("刘易斯","2102",23);
        hashMap.put(s1.getStudentNumber(),s1);
        hashMap.put(s2.getStudentNumber(),s2);
        hashMap.put(s3.getStudentNumber(),s3);
        hashMap.put(s4.getStudentNumber(),s4);
        hashMap.put(s5.getStudentNumber(),s5);
        //
        Map<String, Student> treeMap = new TreeMap<>(hashMap);
        // 遍历整个映射表。输出所有学生的信息。（forEach方法）
        treeMap.forEach(
                (id, stud) -> System.out.println("姓名："+stud.getName()+" 学号："+id+" 年龄："+stud.getAge())
        );
        // 查询学号为2103的学生信息
        Student  student = treeMap.get("2103");   // 记录查询到的学生对象
        System.out.println("学号为"+2103+"的学生信息如下：");
        System.out.println("姓名："+student.getName()+" 学号："+student.getStudentNumber()+" 年龄："+student.getAge());

    }
}
